package com.zjm.creational.singleton.type08;

/**
 * 枚举单例
 */
public class SingletonTest08 {
    public static void main(String[] args) {
        // 模拟10个线程并发获取单例对象
        for (int i = 1; i <= 10; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + " 获取到的实例：" + Singleton.INSTANCE.hashCode());
            }, "线程-" + i).start();
        }
    }
}

enum Singleton{
    INSTANCE;

    public void doSomething() {
        System.out.println("Do something...");
    }
}
